﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Web.Mvc;

namespace CodeContrib.Web.Mvc
{
	public static class CollectionExtensions
	{
		[DebuggerStepThrough]
		public static IEnumerable<T> ForEach<T>(this IEnumerable<T> collection, Action<T> action)
		{
			foreach (var item in collection)
			{
				action(item);
			}

			return collection;
		}

		[DebuggerStepThrough]
		public static SelectList ToSelectList<T>(this IEnumerable<T> collection)
		{
			return new SelectList(collection);
		}

		[DebuggerStepThrough]
		public static SelectList ToSelectList<T>(this IEnumerable<T> collection, object selectedValue)
		{
			return new SelectList(collection, selectedValue);
		}

		[DebuggerStepThrough]
		public static SelectList ToSelectList<T>(this IEnumerable<T> collection, string dataValueField, string dataTextField)
		{
			return new SelectList(collection, dataValueField, dataTextField);
		}

		[DebuggerStepThrough]
		public static SelectList ToSelectList<T>(this IEnumerable<T> collection, string dataValueField, string dataTextField, object selectedValue)
		{
			return new SelectList(collection, dataValueField, dataTextField, selectedValue);
		}
	}
}